$(document).ready(function() {
	//输入提示语
	var promptText = {
		realname : {
			normal : "",
			formatError : "真实姓名必须为汉字。",
			isNull : "真实姓名不能为空。"
		},
		bankname : {
			normal : "",
			isNull : "银行名称不能为空。"
		},
		province : {
			normal : "",
			isNull : "省不能为空。"
		},
		city : {
			normal : "",
			isNull : "市不能为空。"
		},
		subbranch : {
			normal : "",
			isNull : "开户行名称不能为空"
		},
		accountno : {
			normal : "",
			formatError : "银行卡号必须是数字。",
			isNull : "银行卡号不能为空"
		},
		withdrawmoney : {
			normal : "",
			formatError : "提款金额必须为整数!",
			isNull : "请输入提款金额!",
			atLeast : "提款金额最少20元，最多2万元。",
			isOver : "提款金额多于可用提款金额!", 
			insufficient : "您的可提款金额不足!"
		},
		withdrawpassword : {
			normal : "",
			isNull : "提现密码不能为空!"
		}
	};
	
	//可提现金额
	var overage = $("#overage").val();
	//可提现金额判断
	var validateWithdrawMoney = function(){
		var obj = $("#withdraw_money");
		var _money = obj.val();
		if(_money == "" || _money.trim().length == 0)
		{
			Helper.message(promptText.withdrawmoney.isNull);
			return;
		}
		if(!Helper.validata.isInteger(_money))
		{
			Helper.message(promptText.withdrawmoney.formatError);
			return;
			
		} 
		if (_money < 20 || _money > 20000) 
		{
			Helper.message(promptText.withdrawmoney.atLeast);
			return;
		}
		if(overage != "" && overage < 20*100)
		{
			Helper.message(promptText.withdrawmoney.insufficient);
			return;
		}
		if(_money*100 > overage)
		{
			Helper.message(promptText.withdrawmoney.isOver);
			return;
		}
		return true;
	};
	
	var validateWithdrawPassword = function(){
		//检查输入信息
		var obj = $("#withdraw_password");
		var _password = obj.val();
		if(_password == "" || _password.trim().length == 0)
		{
			Helper.message(promptText.withdrawpassword.isNull);
			return;
		}
		return true;
	};
	
	$("#withdrawConfirm").bind('click',function(){
		if(validateWithdrawMoney())
		{
			if($("#3338login").val()==3338){
				new Helper.RemoteQuery({url:Helper.basePath+"/memberCenter/member_operate/goWithDrawConfirm.htm",params:{
					money:$("#withdraw_money").val(),
					bankId:$("#withdraw_bank").val(),
					url:"/page/3338web/memberInfo/bank/withdraw_ok.jsp"
					},renderId:"withDrawConfirmDiv"}).send();
			}else{
				new Helper.RemoteQuery({url:Helper.basePath+"/memberCenter/member_operate/goWithDrawConfirm.htm",params:{
					money:$("#withdraw_money").val(),
					bankId:$("#withdraw_bank").val()
					},renderId:"withDrawConfirmDiv"}).send();
			}
		}
	});
	
	$("#withDrawSubmit").bind('click',function(){
		
		if(validateWithdrawMoney() && validateWithdrawPassword())
		{  if($("#3338login").val()==3338){
			
			var draw338 =  new Helper.RemoteTrans({
					url: Helper.basePath + "/memberCenter/member_operate/withdrawProcess338.htm",
					isAsync : false,
					params:{money:$("#withdraw_money").val(),bankId:$("#withdraw_bank").val(),password:$("#withdraw_password").val()},
					onSuccess: function(result) {
						if(result.returnValue.indexOf("成功，系统处理正常")>=0){
							location.href = "/page/3338web/memberInfo/bank/withdraw_success.jsp";
						}else if(result.returnValue=='您尚未设置提现密码，立即去设置'){
							Helper.message(result.returnValue);
							location.href = "/member_operate/goUpdatePayPwd.htm?url=/page/3338web/memberInfo/txpwd_update.jsp";
						}else{
							Helper.message(result.returnValue);
						}
						}
					});
			draw338.send();
			
		/*	new Helper.RemoteQuery({url:Helper.basePath+"/memberCenter/member_operate/withdrawProcess.htm",params:{
				money:$("#withdraw_money").val(),
				bankId:$("#withdraw_bank").val(),
				password:$("#withdraw_password").val(),
				url:"/page/3338web/memberInfo/bank/withdraw_success.jsp"
				},renderId:"withDrawDiv"}).send();*/
			}else {
				new Helper.RemoteQuery({url:Helper.basePath+"/memberCenter/member_operate/withdrawProcess.htm",params:{
					money:$("#withdraw_money").val(),
					bankId:$("#withdraw_bank").val(),
					password:$("#withdraw_password").val()
					},renderId:"withDrawDiv"}).send();
			}
			
		}
	});
	
	if(0 == $('#bankcardListSize').val())
	{
		alert("你尚未绑定银行卡,请先绑定！");
		if($("#3338login").val()==3338){
			window.location = "/page/3338web/memberInfo/bank/bindbank.jsp";
		}else{
			window.location = "/page/memberinfo/bank/bindbank.jsp";
		}
		
	}
});